<template>
	<el-container>
		<el-container>
            <el-header>
                <el-button type="primary" icon="el-icon-plus" @click="add">新增</el-button>
            </el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter>
					<el-table-column type="selection" width="50" align="center"></el-table-column>
					<!-- <el-table-column label="单号" prop="title" width="180" align="center"></el-table-column> -->
					<el-table-column label="账户名称" prop="sort" align="center"></el-table-column>
					<el-table-column label="账号" prop="cate_name" align="center"></el-table-column>
					<el-table-column label="开户人" prop="cate_name" align="center"></el-table-column>
					<el-table-column label="排序" prop="cate_name" align="center"></el-table-column>
					<el-table-column label="期初余额(¥)" prop="cate_name" align="center"></el-table-column>
					<el-table-column label="当月余额(¥)" prop="cate_name" align="center"></el-table-column>
					<el-table-column label="状态" prop="cate_name" align="center"></el-table-column>
                    <el-table-column label="操作" align="center">
						<template #default="scope">
							<el-button-group>
								<el-button icon="el-icon-EditPen" text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">修改</el-button>
								<el-button icon="el-icon-Delete" text type="primary" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>

export default {
	name: 'user',
	data() {
		return {
			dialog: {
				save: false
			},
			groupFilterText: '',
			group: [],
			apiObj: this.$API.basic.apply.lists,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
			//所需数据选项
			cates: [],
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
		// this.getCate()
	},
	methods: {
		//加载树数据
		async getCate(){
			var res = await this.$API.cms.profile.article_cate.get();
			this.cates = res.data;
		},
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
        goLocation(){
            this.$router.push({
                path: 'storeroomLocation',
            })
        },
		//状态
		async status(row) {
			var reqData = {
				id: row.id,
				is_show :row.is_show
			}
			var res = await this.$API.cms.profile.status.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$message.success("修改成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//删除
		async table_del(row, index) {
			var reqData = { id: row.id }
			var res = await this.$API.cms.profile.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		// async table_del_all(delete_ids) {
		// 	var reqData = { ids: delete_ids }
		// 	var res = await this.$API.cms.article.delete.post(reqData);
		// 	if (res.code == 1) {
		// 		this.$refs.table.refresh()
		// 		this.$message.success("删除成功")
		// 	} else {
		// 		this.$alert(res.message, "提示", { type: 'error' })
		// 	}
		// },
		//批量删除
		// async batch_del() {
		// 	var delete_ids = [];
		// 	this.selection.forEach((item) => {
		// 		delete_ids.push(item.id)
		// 	})
		// 	this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
		// 		type: 'warning'
		// 	}).then(() => {
		// 		this.table_del_all(delete_ids)
		// 	}).catch(() => {
		//
		// 	})
		// },
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
		}
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
</style>
